/*
 * @Author: QinJiu
 * @Date: 2022-07-20 09:09:50
 * @LastEditors: Qinjiu
 * @LastEditTime: 2022-07-20 15:25:03
 * @Description:
 */
import Vue from "vue";
import VueRouter from "vue-router";
import constantRoutes from "./constantRoutes";

Vue.use(VueRouter);

// 创建路由
const createRouter = () => {
  return new VueRouter({
    // mode: 'history', // require service support
    routes: constantRoutes,
  });
};

const router = createRouter();

// 重置路由，退出登录需要
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

// 添加路由
export function addRoutes(routes, parentName) {
  routes?.forEach((route) => {
    if (parentName) {
      router.addRoute(parentName, route);
    } else {
      router.addRoute(route);
    }
  });
}

export default router;
